package com.dengc.intercept;

import com.dengc.pojo.SysUser;
import com.dengc.utils.Contants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SysIntercept implements HandlerInterceptor {

    //重写controller前拦截方法
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        SysUser loginUser = (SysUser) session.getAttribute(Contants.USERSESSION);
        if (loginUser == null){
            response.sendRedirect(request.getContextPath()+"/index.jsp");
            return false;
        }

        return true;
    }
}
